<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select
        v-model="listQuery.channelId"
        filterable
        :filter-method="dataFilter"
        placeholder="选择渠道"
        style="width: 150px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      >
        <el-option
          v-for="item in options"
          :key="item.channelId"
          :label="item.channel_name"
          :value="item.channelId"
        />
      </el-select>
      <el-select
        v-model="listQuery.type"
        filterable
        :filter-method="dataFilter"
        placeholder="选择类型"
        style="width: 150px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      >
        <el-option :value="1" label="同业">同业</el-option>
        <el-option :value="2" label="信息流">信息流</el-option>
        <el-option value="" label="全部">全部</el-option>
      </el-select>
      <el-input
        v-model="listQuery.username"
        placeholder="用户名"
        style="width: 100px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >
        搜索
      </el-button>
      <el-button
        v-waves
        class="filter-item"
        type="success"
        icon="el-icon-plus"
        @click="handleCreate"
      >
        新增
      </el-button>
      <el-popover placement="left" width="300" trigger="click">
        <el-checkbox
          :indeterminate="isIndeterminate"
          v-model="checkAll"
          @change="handleCheckAllChange"
          >全选</el-checkbox
        >
        <div style="margin: 5px 0;"></div>
        <el-checkbox-group
          v-model="checkList"
          @change="handleCheckedCitiesChange"
        >
          <el-checkbox
            v-for="item in columnName"
            :label="item"
            :key="item"
          ></el-checkbox>
        </el-checkbox-group>
        <el-button
          slot="reference"
          class="filter-item"
          type="primary"
          style="float:right"
          >显示列</el-button
        >
      </el-popover>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="tableData"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column
        label="渠道ID"
        align="center"
        width="80"
        v-if="checkList.indexOf('渠道ID') != -1"
      >
        <template slot-scope="{ row }">
          <span>{{ row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="名称"
        class-name="status-col"
        min-width="110"
        v-if="checkList.indexOf('名称') != -1"
      >
        <template slot-scope="{ row }">
          {{ row.nickname }}
        </template>
      </el-table-column>
      <el-table-column
        label="用户名"
        width="150"
        align="center"
        v-if="checkList.indexOf('用户名') != -1"
      >
        <template slot-scope="{ row }">
          <span>{{ row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
        width="80"
        align="center"
        v-if="checkList.indexOf('状态') != -1"
      >
        <template slot-scope="{ row }">
          <el-tag v-if="row.state == 0" type="danger">禁用</el-tag>
          <el-tag v-if="row.state == 1" type="success">启用</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="渠道签名"
        align="center"
        width="110"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('渠道签名') != -1"
      >
        <template slot-scope="{ row }">
          <span>{{ row.sign }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="推广地址"
        align="center"
        min-width="100"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('推广地址') != -1"
      >
        <template slot-scope="{ row }">
          <el-button
            v-clipboard:copy="row.promote_address"
            v-clipboard:success="onCopy"
            v-clipboard:error="onError"
            type="primary"
            size="mini"
          >
            获取
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="类型"
        align="center"
        width="90"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('类型') != -1"
      >
        <template slot-scope="{ row }">
          <el-tag v-if="row.type == 1" type="primary">同业</el-tag>
          <el-tag v-if="row.type == 2" type="primary">信息流</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="扣量"
        align="center"
        width="90"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('扣量') != -1"
      >
        <template slot-scope="{ row }">
          <span>{{ row.kouliang }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="支付方式" align="center" width="90" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <span>{{ row.method }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员价格" align="center" width="90" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <span>{{ row.price }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="登录注册"
        align="center"
        width="90"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('登录注册') != -1"
      >
        <template slot-scope="{ row }">
          <span>{{ row.authLogin === 1 ? '开启' : '关闭' }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="下载"
        align="center"
        width="90"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('下载') != -1"
      >
        <template slot-scope="{ row }">
          <el-tag v-if="row.downloadSwitch === 0" type="danger">关闭</el-tag>
          <el-tag v-if="row.downloadSwitch === 1" type="success">开启</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="版本"
        align="center"
        width="90"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('版本') != -1"
      >
        <template slot-scope="{ row }">
          <span v-if="row.storeOnline === '1'">上架版</span>
          <span v-if="row.storeOnline === '0'">助贷版</span>
        </template>
      </el-table-column>
      <el-table-column
        label="退款开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('退款开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.appStatus"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeASwitch(row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="头部开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('头部开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.headForcePay"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeHead(row)"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="助贷开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('助贷开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.loanSwitchs"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeLoanSwitch(row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="H5助贷开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('H5助贷开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.h5Switch"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeH5Switch(row)"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="h5协议开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('h5协议开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.protocolSwitch"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeProtocolSwitch(row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="身份证识别"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('身份证识别') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.idcardIdentification"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeIdcardIdentification(row)"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="h5贷超开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('h5贷超开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.loanMarket"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeLoanMarket(row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="长短表单开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('长短表单开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.formSwitch"
            active-text="短"
            inactive-text="长"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeFormSwitch(row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="浮窗下载开关"
        align="center"
        min-width="120"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('浮窗下载开关') != -1"
      >
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.floatSwitch"
            active-text="开"
            inactive-text="关"
            active-color="#13ce66"
            inactive-color="#ff4949"
            style="width:100%;margin-top:10px"
            @change="changeFloatSwitch(row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        min-width="510"
        class-name="small-padding fixed-width"
        v-if="checkList.indexOf('操作') != -1"
      >
        <template slot-scope="{ row }">
          <el-button type="primary" size="mini" @click="changeVersion(row)">
            切换版本
          </el-button>
          <el-button
            v-if="row.state == 1"
            type="info"
            size="mini"
            @click="handleEdit(row, 0)"
          >
            禁用
          </el-button>
          <el-button
            v-if="row.state == 0"
            type="success"
            size="mini"
            @click="handleEdit(row, 1)"
          >
            启用
          </el-button>
          <el-button size="mini" type="danger" @click="handleDelete(row)">
            删除
          </el-button>
          <el-button size="mini" type="info" @click="handleResetPwd(row)">
            重置密码
          </el-button>
          <el-button size="mini" type="primary" @click="conf(row)">
            获取渠道配置
          </el-button>
          <el-button size="mini" type="primary" @click="formConf(row)">
            表单配置
          </el-button>
          <!-- <el-button size="mini" type="primary" @click="h5Set(row)">
            表单配置
          </el-button> -->
          <!-- <el-button size="mini" type="success" @click="getSetting(row)">
            认证开关
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getChannelList"
    />

    <el-dialog title="表单配置" :visible.sync="h5dialogFormVisible">
      <el-form label-width="100px" label-position="left">
        <el-form-item
          v-for="(domain, ind) in dynamicValidateForm.domains"
          :label="'助贷字段' + (ind + 1)"
          :key="domain.key"
          prop="value"
        >
          <el-select
            v-model="domain.value"
            clearable
            placeholder="请选择表单问题"
            style="width: 200px;"
            class="filter-item"
            @change="changeOptions"
          >
            <el-option
              v-for="(item, index) in h5Arr"
              :key="index"
              :value="item.value"
              :label="item.label"
              :disabled="item.disabled"
            >
              {{ item.label }}
            </el-option>
          </el-select>
          <el-button
            @click.prevent="removeDomain(domain)"
            style="margin-left:10px"
            v-show="ind != 0"
            >删除</el-button
          >
          <el-button
            v-show="ind + 1 == dynamicValidateForm.domains.length"
            @click="addDomain"
            type="info"
            >新增问题</el-button
          >
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="h5dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitH5()">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="channelReqDto"
        label-position="left"
        label-width="90px"
        style="width: 400px; margin-left:50px;"
      >
        <el-input v-model="channelReqDto.id" type="hidden" />
        <el-form-item label="名称" prop="nickname">
          <el-input v-model="channelReqDto.nickname" />
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select
            v-model="channelReqDto.type"
            clearable
            placeholder="请选择类型"
            style="width: 150px;"
            class="filter-item"
          >
            <el-option :value="1" label="同业">同业</el-option>
            <el-option :value="2" label="信息流">信息流</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名">
          <el-input v-model="channelReqDto.username" />
        </el-form-item>
        <el-form-item label="渠道标识">
          <el-input v-model="channelReqDto.channelSign" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">
          取消
        </el-button>
        <el-button
          type="primary"
          @click="dialogStatus === 'create' ? createData() : updateData()"
        >
          确认
        </el-button>
      </div>
    </el-dialog>

    <el-dialog title="渠道配置" :visible.sync="channelConfdialog">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="channelConf"
        label-position="left"
        label-width="90px"
        style="width: 400px; margin-left:50px;"
      >
        <el-form-item label="渠道ID" label-width="120px">
          <el-input v-model="channelConf.channelId" readonly="readonly" />
        </el-form-item>
        <el-form-item label="用户名" label-width="120px">
          <el-input v-model="channelConf.userName" />
        </el-form-item>
        <el-form-item label="Token" label-width="120px">
          <el-input v-model="channelConf.token" />
        </el-form-item>
        <!-- <el-form-item label="扣量" label-width="120px">
          <el-input v-model="channelConf.kouliang" />
        </el-form-item>
        <el-form-item label="支付方式" label-width="120px">
          <el-input v-model="channelConf.payMethod" />
        </el-form-item>
        <el-form-item label="会员价格" label-width="120px">
          <el-input v-model="channelConf.vipprice" />
        </el-form-item> -->
        <el-form-item label="类型" label-width="120px">
          <el-radio-group v-model="channelConf.type" size="small">
            <el-radio :label="1">
              同业
            </el-radio>
            <el-radio :label="2">
              信息流
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="登录注册" label-width="120px">
          <el-radio-group v-model="channelConf.needAuthLogin" size="small">
            <el-radio :label="1">
              开启
            </el-radio>
            <el-radio :label="0">
              关闭
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="下载应用" label-width="120px">
          <el-radio-group v-model="channelConf.downloadSwitch" size="small">
            <el-radio :label="1">
              开启
            </el-radio>
            <el-radio :label="0">
              关闭
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="认证展示" label-width="120px">
          <el-radio-group v-model="channelConf.turnSwitch" size="small">
            <el-radio :label="1">
              投放面
            </el-radio>
            <el-radio :label="0">
              过审面
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="安卓上架开关" label-width="120px">
          <el-radio-group v-model="channelConf.androidSwitch" size="small">
            <el-radio :label="0">
              开
            </el-radio>
            <el-radio :label="1">
              关
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="自动跳转" label-width="120px">
          <el-radio-group v-model="channelConf.jumpPage" size="small">
            <el-radio :label="1">
              开启
            </el-radio>
            <el-radio :label="0">
              关闭
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="跳转停留秒数"
          v-if="radioState == 1"
          label-width="120px"
        >
          <el-input type="number" v-model="channelConf.milliSeconds" />
        </el-form-item>
        <el-form-item label="渠道价格" label-width="120px">
          <el-input v-model="channelConf.price" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="channelConfdialog = false">
          取消
        </el-button>
        <el-button type="primary" @click="updateChannelSetting()">
          确认
        </el-button>
      </div>
    </el-dialog>
    <el-dialog title="动态表单配置" :visible.sync="formConfdialog">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="formConfig"
        label-position="left"
        label-width="90px"
        style=" margin-left:50px;"
      >
        <el-checkbox
          class="trends"
          v-if="trendsForm"
          v-model="trendsChecked"
          @change="changeTrendsChecked"
          border
          >全选</el-checkbox
        >
        <el-checkbox-group v-model="checkedList">
          <el-checkbox
            class="trends_form"
            v-for="item in trendsForm"
            @change="changeTrendsItem"
            :key="item.id"
            :label="item.id"
            border
            >{{ item.labelName }}</el-checkbox
          >
        </el-checkbox-group>
        <el-divider></el-divider>
        <el-checkbox
          class="trends"
          v-if="trendsForm"
          @change="changeTrendsMore"
          v-model="assetsChecked"
          border
          >资质情况(可多选)</el-checkbox
        >
        <el-checkbox
          class="trends"
          v-if="trendsForm"
          v-model="trendsChecked2"
          @change="changeTrendsChecked2"
          border
          >全选</el-checkbox
        >
        <el-checkbox-group v-model="checkedList2">
          <el-checkbox
            class="trends_form"
            v-for="items in newMultipleChoice"
            @change="changeTrendsItem2"
            :key="items.index"
            :label="items.label"
            border
            >{{ items.label }}</el-checkbox
          >
        </el-checkbox-group>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="formConfdialog = false">
          取消
        </el-button>
        <el-button type="primary" @click="updateElementPackage()">
          确认
        </el-button>
      </div>
    </el-dialog>

    <el-dialog title="认证开关配置" :visible.sync="channelauthConfdialog">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="channelauthConf"
        label-position="left"
        label-width="90px"
        style="width: 400px; margin-left:50px;"
      >
        <!-- <el-form-item label="头部开关" label-width="170px">
          <el-radio-group v-model="channelauthConf.headForcePay" size="small">
            <el-radio :label="1">
              是
            </el-radio>
            <el-radio :label="0">
              否
            </el-radio>
          </el-radio-group>
        </el-form-item> -->
        <el-form-item label="用户需要认证" label-width="170px">
          <el-radio-group v-model="channelauthConf.authSwitch" size="small">
            <el-radio :label="1">
              是
            </el-radio>
            <el-radio :label="0">
              否
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否开启机构匹配" label-width="170px">
          <el-radio-group v-model="channelauthConf.pickSwitch" size="small">
            <el-radio :label="1">
              是
            </el-radio>
            <el-radio :label="0">
              否
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-switch
          v-model="identity"
          active-text="身份证认证"
          active-color="#13ce66"
          inactive-color="#ff4949"
          style="width:100%;margin-top:10px"
        />
        <div v-if="identity === true">
          <el-form-item label="真实姓名" label-width="170px">
            <el-radio-group v-model="channelauthConf.idcard.name" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="身份证号码" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.idcard.idcard"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <el-switch
          v-model="bankcard"
          active-text="银行卡"
          active-color="#13ce66"
          inactive-color="#ff4949"
          style="width:100%;margin-top:10px"
        />
        <div v-if="bankcard === true">
          <!-- <el-form-item label="姓名" label-width="170px">
            <el-radio-group v-model="channelauthConf.bankcard.name" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item> -->
          <!-- <el-form-item label="身份证号码" label-width="170px">
            <el-radio-group v-model="channelauthConf.bankcard.idcard" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item> -->
          <el-form-item label="银行名称" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.bankcard.bank"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <el-form-item label="银行卡号码" label-width="170px">
            <el-radio-group v-model="channelauthConf.bankcard.bankNo" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item> -->
          <el-form-item label="手机号码" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.bankcard.phone"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="验证码" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.bankcard.smsCode"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <el-switch
          v-model="base"
          active-text="用户基本信息"
          active-color="#13ce66"
          inactive-color="#ff4949"
          style="width:100%;margin-top:10px"
        />
        <div v-if="base === true">
          <el-form-item label="性别" label-width="170px">
            <el-radio-group v-model="channelauthConf.base.sex" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="贷款金额" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.loanAmount"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="贷款期限" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.loanTerm"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="贷款原因" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.loanReason"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="社保" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.socialInsurance"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="公积金" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.accumulationFund"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="信用卡额度" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.creditQuota"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="微粒贷" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.microLoan"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="车产" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.carOwner"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="房产" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.houseOwner"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="保险" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.insuranceOwner"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="职业信息" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.occupation"
              size="small"
              @change="jobChange"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="所在地区" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.provinceAndCity"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <el-form-item label="住址信息" label-width="170px">
            <el-radio-group v-model="channelauthConf.base.address" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item> -->
          <el-form-item label="芝麻分" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.zhimaPoint"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="文化程度" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.highestEdu"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="信用记录" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.base.creditCardHistory"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <el-switch
          v-model="officeWorker"
          active-text="上班族"
          active-color="#13ce66"
          inactive-color="#ff4949"
          style="width:100%;margin-top:10px"
        />
        <div v-if="job" style="width:100%;margin-left:20px">
          <h2>上班族:</h2>
          <el-form-item label="公司类型" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.officeWorker.companyType"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="月收入" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.officeWorker.income"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="工资支付方式" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.officeWorker.incomeSource"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="工龄" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.officeWorker.companyWorkingYear"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <el-form-item label="公积金" label-width="170px">
            <el-radio-group v-model="channelauthConf.officeWorker.accumulationFund" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="社保" label-width="170px">
            <el-radio-group v-model="channelauthConf.officeWorker.socialInsurance" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item> -->
        </div>
        <el-switch
          v-model="businessOwners"
          active-text="企业主"
          active-color="#13ce66"
          inactive-color="#ff4949"
          style="width:100%;margin-top:10px"
        />
        <div v-if="job" style="width:100%;margin-left:20px">
          <h2>企业主:</h2>
          <el-form-item label="企业流水" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.businessOwners.enterpriseFlow"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="营业执照" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.businessOwners.businessLicense"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="经营年限" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.businessOwners.enterpriseTerm"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <el-switch
          v-model="professional"
          active-text="自由职业者"
          active-color="#13ce66"
          inactive-color="#ff4949"
          style="width:100%;margin-top:10px"
        />
        <div v-if="job" style="width:100%;margin-left:20px">
          <h2>自由职业者:</h2>
          <el-form-item label="月收入" label-width="170px">
            <el-radio-group
              v-model="channelauthConf.professional.income"
              size="small"
            >
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <!-- <el-switch
          v-model="contactInformation"
          active-text="联系信息"
          active-color="#13ce66"
          inactive-color="#ff4949"
          style="width:100%;margin-top:10px"
        />
        <div v-if="contactInformation === true ">
          <el-form-item label="所在地区" label-width="170px">
            <el-radio-group v-model="channelauthConf.contactInformation.provinceAndCity" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="住址信息" label-width="170px">
            <el-radio-group v-model="channelauthConf.contactInformation.address" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="请输入紧急联系人姓名" label-width="170px">
            <el-radio-group v-model="channelauthConf.contactInformation.contactName" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="请输入紧急联系人手机号" label-width="170px">
            <el-radio-group v-model="channelauthConf.contactInformation.contactPhone" size="small">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="channelauthConfdialog = false">
          取消
        </el-button>
        <el-button type="primary" @click="updateChannelSettingv2()">
          确认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
const column = [
  '渠道ID',
  '名称',
  '用户名',
  '状态',
  '渠道签名',
  '推广地址',
  '类型',
  '扣量',
  '登录注册',
  '下载',
  '版本',
  '退款开关',
  '头部开关',
  '非会员客服开关',
  '助贷开关',
  'H5助贷开关',
  'h5协议开关',
  '身份证识别',
  '长短表单开关',
  'h5贷超开关',
  '浮窗下载开关',
  '操作'
];
import {
  getChannelIdAndNick,
  changeVersion,
  loanSwitch,
  couponSwitch,
  protocolSwitch
} from '@/api/user';
import {
  getChannelList,
  addChannel,
  editState,
  deleteById,
  createSign,
  updateForceHeadLock,
  powerSwitch,
  updateChannelSetting,
  getChannelSetting,
  resetpwd,
  getSetting,
  updateChannelSettingv2,
  refundApplication,
  h5Switch,
  commonCustom,
  addByChennelId,
  idSwitch,
  defaultSwitch,
  formSwitch,
  loanMarket,
  floatSwitch,
  getAllElement,
  editElementPackage
} from '@/api/channel';
import waves from '@/directive/waves'; // waves directive
import Pagination from '@/components/Pagination'; // secondary package based on el-pagination
export default {
  name: 'Channellist',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      h5Arr: [
        { value: '您需要的额度', label: '您需要的额度', disabled: false },
        {
          value: '您的芝麻信用分数',
          label: '您的芝麻信用分数',
          disabled: false
        },
        {
          value: '您名下的车产信息',
          label: '您名下的车产信息',
          disabled: false
        },
        { value: '您是否购买保险', label: '您是否购买保险', disabled: false },
        { value: '您的职业', label: '您的职业', disabled: false },
        {
          value: '您缴纳的本地公积金',
          label: '您缴纳的本地公积金',
          disabled: false
        }
      ],
      dynamicValidateForm: {
        domains: [
          {
            value: ''
          },
          {
            value: ''
          }
        ]
      },
      checkAll: false,
      isIndeterminate: true,
      checkList: [
        '渠道ID',
        '名称',
        '状态',
        '渠道签名',
        '推广地址',
        '版本',
        'H5助贷开关',
        '操作'
      ],
      columnName: column,
      testCopy: '',
      tableData: [],
      total: 0,
      tableKey: 0,
      listQuery: {
        current: 1,
        size: 10,
        apk: '',
        nickname: '',
        username: ''
      },
      channelReqDto: {
        id: undefined,
        gmtDatetime: new Date(),
        sysKey: '',
        sysLabel: '',
        sysValue: '',
        type: ''
      },
      channelConf: {
        id: undefined,
        channelId: '',
        kouliang: '',
        payMethod: '',
        vipprice: '',
        token: ''
      },
      formConfig: {
        id: undefined,
        channelId: '',
        kouliang: '',
        payMethod: '',
        vipprice: '',
        token: ''
      },
      formChannelId: '',
      trendsForm: [],
      multipleChoice: [],
      newMultipleChoice: [],
      trendsChecked: false,
      trendsChecked2: false,
      assetsChecked: false,
      checkedList: [],
      checkedList2: [],
      channelauthConf: {
        id: undefined
      },
      job: false,
      openauth: false,
      bankcard: false,
      identity: false,
      base: false,
      officeWorker: false,
      businessOwners: false,
      professional: false,
      contactInformation: false,
      dialogFormVisible: false,
      channelConfdialog: false,
      formConfdialog: false,
      channelauthConfdialog: false,
      dialogStatus: '',
      textMap: {
        update: '修改',
        create: '新增'
      },
      dialogPvVisible: false,
      rules: {
        type: [
          { required: true, message: 'type is required', trigger: 'change' }
        ],
        timestamp: [
          {
            type: 'date',
            required: true,
            message: 'timestamp is required',
            trigger: 'change'
          }
        ],
        nickname: [{ required: true, message: '名称必填', trigger: 'blur' }],
        type: [{ required: true, message: '请选择类型', trigger: 'blur' }]
      },
      downloadLoading: false,
      optionsCopy: [],
      options: [],
      listLoading: false,
      radioState: null
    };
  },
  created() {
    this.getChannelList(this.listQuery);
    this.getChannelIdAndNick();
  },
  watch: {
    'channelConf.jumpPage'(newVal, oldVal) {
      this.radioState = newVal;
    },
    'dynamicValidateForm.domains': {
      handler(newArr) {
        // 一开始都设置为允许使用
        this.h5Arr = this.h5Arr.map(item => {
          item.disabled = false;
          return item;
        });
        // 将选过的设置为禁用
        newArr.forEach(x => {
          this.h5Arr.forEach(y => {
            if (x.value === y.value) {
              y.disabled = true;
            }
          });
        });
      },
      deep: true
    }
  },
  methods: {
    submitH5() {
      let sortAndIdDto = [];
      this.dynamicValidateForm.domains.forEach((item, index) => {
        if (item.value) {
          sortAndIdDto.push({
            channelId: this.h5channelId,
            problem: item.value,
            serialNo: index + 1
          });
        }
      });
      addByChennelId(sortAndIdDto).then(res => {});
    },
    removeDomain(item) {
      var index = this.dynamicValidateForm.domains.indexOf(item);
      if (index !== -1) {
        this.dynamicValidateForm.domains.splice(index, 1);
      }
    },
    addDomain() {
      this.dynamicValidateForm.domains.push({
        value: '',
        key: Date.now()
      });
    },
    h5Set(row) {
      this.dynamicValidateForm.domains = [
        {
          value: ''
        },
        {
          value: ''
        }
      ];
      this.h5dialogFormVisible = true;
      this.h5channelId = row.id;
    },
    handleCheckAllChange(val) {
      this.checkList = val ? column : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.columnName.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.columnName.length;
    },
    changeHead(row) {
      this.channelauthConf.channelId = row.id;
      // this.channelauthConf.headForcePay = row.headForcePay ? 1 : 0
      updateForceHeadLock(this.channelauthConf).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新认证配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新认证配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeDefault(row) {
      if (row.default_switch === 1) {
        row.default_switch = 0;
      } else {
        row.default_switch = 1;
      }
      const memberCardDto = {
        defaultSwitch: row.default_switch,
        channelId: row.id
      };
      defaultSwitch(memberCardDto).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeFloatSwitch(row) {
      // 开关状态：0关 1开
      if (row.float_switch === 1) {
        row.float_switch = 0;
      } else {
        row.float_switch = 1;
      }
      const eswitch = { floatSwitch: row.float_switch, channelId: row.id };
      floatSwitch(eswitch).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeLoanMarket(row) {
      // 开关状态：0关 1开
      if (row.loan_market_switch === 1) {
        row.loan_market_switch = 0;
      } else {
        row.loan_market_switch = 1;
      }
      const refundApplicationDto = {
        loanMarketSwitch: row.loan_market_switch,
        channelId: row.id
      };
      loanMarket(JSON.parse(JSON.stringify(refundApplicationDto))).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeASwitch(row) {
      // 开关状态：0关 1开
      if (row.application_status === 1) {
        row.application_status = 0;
      } else {
        row.application_status = 1;
      }
      const refundApplicationDto = {
        applicationStatus: row.application_status,
        channelId: row.id
      };
      refundApplication(JSON.parse(JSON.stringify(refundApplicationDto))).then(
        res => {
          if (res.data.code === 200) {
            this.$notify({
              title: '更新配置',
              message: '更新成功！',
              type: 'success',
              duration: 2000
            });
            this.getChannelList(this.listQuery);
          } else {
            this.$notify({
              title: '更新配置',
              message: '更新失败！',
              type: 'fail',
              duration: 2000
            });
          }
        }
      );
    },
    changeFormSwitch(row) {
      // 开关状态：0关 1开
      if (row.form_switch === 1) {
        row.form_switch = 0;
      } else {
        row.form_switch = 1;
      }
      const eswitch = { formSwitch: row.form_switch, channelId: row.id };
      formSwitch(eswitch).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeEnableSwitch(row) {
      // 开关状态：0关 1开
      if (row.enable === 1) {
        row.enable = 0;
      } else {
        row.enable = 1;
      }
      const eswitch = { enable: row.enable, channelId: row.id };
      powerSwitch(eswitch).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeLoanSwitch(row) {
      // 开关状态：0关 1开
      if (row.loan_switch == 1) {
        row.loan_switch = 0;
      } else {
        row.loan_switch = 1;
      }
      const refundApplicationDto = {
        loanSwitch: row.loan_switch,
        channelId: row.id
      };
      loanSwitch(refundApplicationDto).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeCouponSwitch(row) {
      // 开关状态：0关 1开
      if (row.coupon_switch == 1) {
        row.coupon_switch = 0;
      } else {
        row.coupon_switch = 1;
      }
      const refundApplicationDto = {
        couponSwitch: row.coupon_switch,
        channelId: row.id
      };
      couponSwitch(refundApplicationDto).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeProtocolSwitch(row) {
      // 开关状态：0关 1开
      if (row.protocol_switch == 1) {
        row.protocol_switch = 0;
      } else {
        row.protocol_switch = 1;
      }
      const refundApplicationDto = {
        protocolSwitch: row.protocol_switch,
        channelId: row.id
      };
      protocolSwitch(refundApplicationDto).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeCustom(row) {
      if (row.common_custom === 1) {
        row.common_custom = 0;
      } else {
        row.common_custom = 1;
      }
      const memberCardDto = {
        commonCustom: row.common_custom,
        channelId: row.id
      };
      commonCustom(memberCardDto).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeH5Switch(row) {
      if (row.h5_switch == 1) {
        row.h5_switch = 0;
      } else {
        row.h5_switch = 1;
      }
      const refundApplicationDto = {
        h5Switch: row.h5_switch,
        channelId: row.id
      };
      h5Switch(refundApplicationDto).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeIdcardIdentification(row) {
      if (row.idcard_identification === 1) {
        row.idcard_identification = 0;
      } else {
        row.idcard_identification = 1;
      }
      const memberCardDto = {
        idSwitch: row.idcard_identification,
        channelId: row.id
      };
      idSwitch(memberCardDto).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    changeTrendsMore() {
      if (!this.assetsChecked) {
        this.checkedList2 = [];
        this.trendsChecked2 = false;
      }
    },
    changeTrendsChecked() {
      if (this.trendsChecked) {
        const newArr = this.trendsForm.map(item => {
          return item.id;
        });
        this.checkedList = newArr;
        this.checkedList2 = this.multipleChoice;
        this.trendsChecked2 = true;
        this.assetsChecked = true;
      } else {
        this.checkedList = [];
        this.checkedList2 = [];
        this.trendsChecked2 = false;
        this.assetsChecked = false;
      }
    },
    changeTrendsChecked2() {
      if (this.trendsChecked2) {
        this.checkedList2 = this.multipleChoice;
        this.assetsChecked = true;
      } else {
        this.checkedList2 = [];
        this.assetsChecked = false;
      }
      if (
        this.trendsForm.length === this.checkedList.length &&
        this.multipleChoice.length === this.checkedList2.length
      ) {
        this.trendsChecked = true;
      } else {
        this.trendsChecked = false;
      }
    },
    changeTrendsItem() {
      if (
        this.trendsForm.length === this.checkedList.length &&
        this.multipleChoice.length === this.checkedList2.length
      ) {
        this.trendsChecked = true;
      } else {
        this.trendsChecked = false;
      }
    },
    changeTrendsItem2() {
      this.assetsChecked = this.checkedList2.length > 0 ? true : false;
      this.trendsChecked2 =
        this.multipleChoice.length === this.checkedList2.length ? true : false;
      if (
        this.multipleChoice.length === this.checkedList2.length &&
        this.trendsForm.length === this.checkedList.length
      ) {
        this.trendsChecked = true;
      } else {
        this.trendsChecked = false;
      }
    },
    dataFilter(val) {
      this.value = val;
      if (val) {
        // val存在
        this.options = this.optionsCopy.filter(item => {
          if (
            !!~item.channel_name.indexOf(val) ||
            !!~item.channel_name.toUpperCase().indexOf(val.toUpperCase())
          ) {
            return true;
          }
        });
      } else {
        // val为空时，还原数组
        this.options = this.optionsCopy;
      }
    },
    async getChannelIdAndNick() {
      const res = await getChannelIdAndNick(this.listQuery);
      res.data.data.forEach(element => {
        if (element.channel_name !== null) {
          this.optionsCopy.push(element);
          this.options.push(element);
        }
      });
    },
    // 获取列表
    async getChannelList(listQuery) {
      const res = await getChannelList(this.listQuery);
      this.tableData = res.data.data.records;
      this.tableData.forEach(e => {
        e.headForcePay = e.headForcePay === 1;
        e.enableSwitch = e.enable === 1;
        e.appStatus = e.application_status == 1;
        e.loanSwitchs = e.loan_switch == 1;
        e.commonSwitch = e.common_custom == 1;
        e.couponSwitch = e.coupon_switch == 1;
        e.h5Switch = e.h5_switch == 1;
        e.protocolSwitch = e.protocol_switch == 1;
        e.idcardIdentification = e.idcard_identification == 1;
        e.defaultSwitch = e.default_switch == 1;
        e.loanMarket = e.loan_market_switch == 1;
        e.formSwitch = e.form_switch == 1;
        e.floatSwitch = e.float_switch == 1;
      });
      this.total = res.data.data.total;
    },
    handleFilter() {
      this.listQuery.current = 1;
      if (this.listQuery.channelId === undefined) {
        this.getChannelList(this.listQuery);
      } else {
        this.options.forEach(element => {
          if (element.channelId === this.listQuery.channelId) {
            this.listQuery.nickname = element.channel_name;
            this.getChannelList(this.listQuery);
          }
        });
      }
    },
    jobChange() {
      if (this.channelauthConf.base.occupation === 1) {
        this.job = true;
      } else {
        this.job = false;
      }
    },
    async changeVersion(row) {
      var version = {};
      version.id = row.channelSettingId;
      if (row.storeOnline === '1') {
        version.storeOnline = '0';
      } else {
        version.storeOnline = '1';
      }
      const res = await changeVersion(version);
      if (res.data.code === 200) {
        this.$notify({
          title: '切换成功',
          message: '切换成功',
          type: 'success',
          duration: 2000
        });
        this.getChannelList(this.listQuery);
      } else {
        this.$notify({
          title: '切换失败',
          message: '切换失败',
          type: 'fail',
          duration: 2000
        });
      }
    },
    onCopy(e) {
      this.$notify({
        title: '获取链接',
        message: '内容:' + e.text + '已复制到您的剪切板',
        type: 'success',
        duration: 2000
      });
    },
    onError(e) {
      this.$notify({
        title: '获取链接',
        message: '内容:' + e.text + '获取失败',
        type: 'fail',
        duration: 2000
      });
    },
    resetTemp() {
      this.channelReqDto = {
        id: undefined,
        apk: '',
        nickname: '',
        username: ''
      };
    },
    conf(row) {
      getChannelSetting({ id: row.id }).then(res => {
        if (res.data.code === 200) {
          this.channelConfdialog = true;
          this.channelConf = res.data.data;
        } else {
          this.$notify({
            title: '获取配置',
            message: '获取失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    formConf(row) {
      this.formChannelId = row.id;
      this.checkedList = [];
      this.checkedList2 = [];
      this.trendsChecked = false;
      this.trendsChecked2 = false;
      this.assetsChecked = false;
      getAllElement({ id: row.id }).then(res => {
        if (res.data.code === 200) {
          this.formConfdialog = true;
          if (res.data.data && res.data.data.length > 0) {
            this.trendsForm = res.data.data.filter(item => {
              return item.inputType !== 'assets';
            });
            const assets = res.data.data.filter(item => {
              return item.inputType === 'assets';
            });
            const newLabel = assets[0].labelValues.split(',');
            const newAssets = newLabel.map((item, index) => {
              const a = {};
              a.index = index;
              a.label = item;
              item = a;
              return a;
            });
            this.newMultipleChoice = newAssets;

            this.multipleChoice = newLabel;
            const newArr = this.trendsForm
              .filter(item => {
                return item.isChecked === 'Y';
              })
              .map(item => {
                return item.id;
              });
            this.checkedList = newArr;
            const newArr2 = assets[0].assets.split(',');
            this.checkedList2 = newArr2;
            this.assetsChecked = this.checkedList2.length > 0 ? true : false;
            this.trendsChecked2 =
              this.multipleChoice.length === this.checkedList2.length
                ? true
                : false;
            if (
              this.multipleChoice.length === this.checkedList2.length &&
              this.trendsForm.length === this.checkedList.length
            ) {
              this.trendsChecked = true;
            } else {
              this.trendsChecked = false;
            }
          }
        } else {
          this.$notify({
            title: '获取配置',
            message: '获取失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    updateElementPackage() {
      if (this.assetsChecked) {
        this.checkedList.push(13);
      }
      this.checkedList.filter(item => {
        if (item) {
          return item;
        }
      });
      const newCheckedList2 = [];
      this.newMultipleChoice.map(item => {
        if (this.checkedList2.join(',').includes(item.label)) {
          newCheckedList2.push(item.label);
        }
      });
      console.log(newCheckedList2);
      const params = {
        id: this.formChannelId,
        assets: newCheckedList2
      };
      editElementPackage(params, this.checkedList).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
        this.formConfdialog = false;
      });
    },
    // 获取认证
    getSetting(row) {
      getSetting({ id: row.id }).then(res => {
        if (res.data.code === 200) {
          this.channelauthConfdialog = true;
          this.channelauthConf = res.data.data;
          // 银行卡
          if (this.channelauthConf.auth.bankcard === 1) {
            this.bankcard = true;
          } else {
            this.bankcard = false;
          }
          // 基本信息
          if (this.channelauthConf.auth.baseinfo === 1) {
            this.base = true;
          } else {
            this.base = false;
          }
          // 身份证
          if (this.channelauthConf.auth.idcard === 1) {
            this.identity = true;
          } else {
            this.identity = false;
          }
          // 联系人
          if (this.channelauthConf.auth.contact === 1) {
            this.contactInformation = true;
          } else {
            this.contactInformation = false;
          }
          if (this.channelauthConf.base.occupation === 1) {
            this.job = true;
          } else {
            this.job = false;
          }
        } else {
          this.$notify({
            title: '获取认证配置',
            message: '获取失败！',
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    async updateChannelSettingv2() {
      // 银行卡
      if (this.bankcard) {
        this.channelauthConf.auth.bankcard = 1;
      } else {
        this.channelauthConf.auth.bankcard = 0;
      }
      if (
        this.channelauthConf.bankcard.name === 0 &&
        this.channelauthConf.bankcard.idcard === 0 &&
        this.channelauthConf.bankcard.bank === 0 &&
        this.channelauthConf.bankcard.bankNo === 0 &&
        this.channelauthConf.bankcard.phone === 0 &&
        this.channelauthConf.bankcard.smsCode === 0
      ) {
        this.channelauthConf.auth.bankcard = 0;
      }
      // 基本信息
      if (this.base) {
        this.channelauthConf.auth.baseinfo = 1;
      } else {
        this.channelauthConf.auth.baseinfo = 0;
      }
      if (
        this.channelauthConf.base.sex === 0 &&
        this.channelauthConf.base.loanAmount === 0 &&
        this.channelauthConf.base.loanTerm === 0 &&
        this.channelauthConf.base.loanReason === 0 &&
        this.channelauthConf.base.socialInsurance === 0 &&
        this.channelauthConf.base.accumulationFund === 0 &&
        this.channelauthConf.base.creditQuota === 0 &&
        this.channelauthConf.base.microLoan === 0 &&
        this.channelauthConf.base.carOwner === 0 &&
        this.channelauthConf.base.houseOwner === 0 &&
        this.channelauthConf.base.insuranceOwner === 0 &&
        this.channelauthConf.base.occupation === 0
      ) {
        this.channelauthConf.auth.baseinfo = 0;
      }
      // 身份证
      if (this.identity) {
        this.channelauthConf.auth.idcard = 1;
      } else {
        this.channelauthConf.auth.idcard = 0;
      }
      if (
        this.channelauthConf.idcard.name === 0 &&
        this.channelauthConf.idcard.idcard === 0
      ) {
        this.channelauthConf.auth.idcard = 0;
      }
      // 联系人
      if (this.contactInformation) {
        this.channelauthConf.auth.contact = 1;
      } else {
        this.channelauthConf.auth.contact = 0;
      }
      if (
        this.channelauthConf.contactInformation.provinceAndCity === 0 &&
        this.channelauthConf.contactInformation.address === 0 &&
        this.channelauthConf.contactInformation.contactName === 0 &&
        this.channelauthConf.contactInformation.contactPhone === 0
      ) {
        this.channelauthConf.auth.contact = 0;
      }
      // job
      // if (this.channelauthConf.officeWorker.companyType === 0 &&
      // this.channelauthConf.officeWorker.companyType === 0 &&
      // this.channelauthConf.officeWorker.companyType === 0 &&
      // this.channelauthConf.professional.income === 0 &&
      // this.channelauthConf.businessOwners.enterpriseFlow === 0 &&
      // this.channelauthConf.businessOwners.businessLicense === 0) {
      //   this.channelauthConf.base.occupation = 0
      // }
      if (
        this.channelauthConf.auth.contact === 0 &&
        this.channelauthConf.auth.idcard === 0 &&
        this.channelauthConf.auth.baseinfo === 0 &&
        this.channelauthConf.auth.bankcard === 0
      ) {
        this.channelauthConf.authSwitch = 0;
      }
      await updateChannelSettingv2(this.channelauthConf).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新认证配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
        } else {
          this.$notify({
            title: '更新认证配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
        this.channelauthConfdialog = false;
      });
      this.getChannelList(this.listQuery);
    },
    updateChannelSetting() {
      updateChannelSetting(this.channelConf).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '更新配置',
            message: '更新成功！',
            type: 'success',
            duration: 2000
          });
          this.getChannelList(this.listQuery);
        } else {
          this.$notify({
            title: '更新配置',
            message: '更新失败！',
            type: 'fail',
            duration: 2000
          });
        }
        this.channelConfdialog = false;
      });
    },
    handleEdit(row, statetype) {
      if (row.state === statetype) {
        this.$notify({
          title: '更新状态',
          message: '不能更改相同的状态',
          type: 'fail',
          duration: 2000
        });
      } else {
        editState({ id: row.id, state: statetype }).then(res => {
          if (res.data.code === 200) {
            this.$notify({
              title: '更新状态',
              message: '更新成功！',
              type: 'success',
              duration: 2000
            });
            this.getChannelList();
          } else {
            this.$notify({
              title: '更新状态',
              message: '更新失败！',
              type: 'fail',
              duration: 2000
            });
          }
        });
      }
    },
    handleCreate() {
      this.resetTemp();
      createSign({ data: new Date() }).then(res => {
        this.channelReqDto.channelSign = res.data.data;
        if (res.data.code === 200) {
          this.dialogStatus = 'create';
          this.dialogFormVisible = true;
        } else {
          this.$notify({
            title: '错误',
            message: '获取签名失败',
            type: 'fail',
            duration: 2000
          });
        }
      });
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate();
      });
    },
    createData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          addChannel(this.channelReqDto).then(res => {
            if (res.data.code === 200) {
              this.dialogFormVisible = false;
              this.$notify({
                title: 'Success',
                message: 'create Successfully',
                type: 'success',
                duration: 2000
              });
            } else {
              this.$notify({
                title: '错误',
                message: res.data.msg,
                type: 'fail',
                duration: 2000
              });
            }
            this.getChannelList();
          });
        }
      });
    },
    handleDelete(row) {
      var that = this;
      this.$confirm('删除提示！', '确认删除吗？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        deleteById({ id: row.id }).then(res => {
          if (res.data.code === 200) {
            that.getChannelList();
          } else {
            this.$notify({
              title: '错误',
              message: res.data.msg,
              type: 'fail',
              duration: 2000
            });
          }
        });
      });
    },
    handleResetPwd(row) {
      resetpwd({ id: row.id }).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: 'Success',
            message: res.data.msg,
            type: 'success',
            duration: 2000
          });
        } else {
          this.$notify({
            title: '错误',
            message: res.data.msg,
            type: 'fail',
            duration: 2000
          });
        }
      });
    },
    getSortClass: function(key) {
      const sort = this.listQuery.sort;
      return sort === `+${key}` ? 'ascending' : 'descending';
    }
  }
};
</script>

<style scoped>
.pic {
  width: 150px;
  margin-top: 10px;
  margin-left: 10px;
}
.ok {
  margin-left: 10px;
  margin-top: 10px;
  font-weight: 5 00;
  color: rgb(35, 248, 124);
}
.fail {
  margin-left: 10px;
  margin-top: 10px;
  font-weight: 5 00;
  color: rgb(240, 174, 76);
}
.info {
  margin-left: 10px;
  margin-top: 10px;
  font-weight: 5 00;
}
.info-name {
  margin-left: 50px;
  margin-top: 10px;
  color: rgb(172, 176, 177);
}
.title {
  margin-top: 10px;
  margin-left: 10px;
  font-size: 20px;
  font-weight: 400;
}
.box {
  margin-top: 10px;
  width: 100%;
  border: solid rgb(138, 219, 230) 2px;
}
.nick {
  font-size: 30px;
  font-weight: 600;
}
.link-top {
  margin-left: 10px;
  margin-top: 10px;
  width: 100%;
  height: 2px;
  border-top: solid rgb(138, 219, 230) 2px;
}
.link-title {
  margin-left: 10px;
  margin-top: 10px;
  width: 80px;
  height: 2px;
  border-top: solid rgb(172, 176, 177) 2px;
}
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
.trends {
  margin-bottom: 10px;
  font-weight: bolder;
}
.trends_form {
  margin-top: 10px;
}
</style>
